@model ShippingProviderSearchModel

@{    
    //page title
    ViewBag.Title = T("Admin.Configuration.Shipping.Providers.Title").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Shipping providers");
}

<nop-antiforgery-token />
<div class="content-header clearfix">
    <h1 class="pull-left">
        @T("Admin.Configuration.Shipping.Providers.Title")
    </h1>
    <div class="pull-right">
        &nbsp;
        @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.ShippingProviderListButtons })
    </div>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    <p>
                        @T("Admin.Configuration.Shipping.Providers.DownloadMorePlugins")
                    </p>

                    @await Html.PartialAsync("Table", new DataTablesModel
                    {
                        Name = "shippingproviders-grid",
                        UrlRead = new DataUrl("Providers", "Shipping", null),
                        UrlUpdate = new DataUrl("ProviderUpdate", "Shipping", null),
                        Length = Model.PageSize,
                        LengthMenu = Model.AvailablePageSizes,
                        ColumnCollection = new List<ColumnProperty>
                            {
                                new ColumnProperty(nameof(ShippingProviderModel.FriendlyName))
                                {
                                    Title = T("Admin.Configuration.Shipping.Providers.Fields.FriendlyName").Text,
                                    Width = "250"
                                },
                                new ColumnProperty(nameof(ShippingProviderModel.SystemName))
                                {
                                    Title = T("Admin.Configuration.Shipping.Providers.Fields.SystemName").Text,
                                    Width = "250"
                                },
                                new ColumnProperty(nameof(ShippingProviderModel.LogoUrl))
                                {
                                    Title = T("Admin.Configuration.Shipping.Providers.Fields.Logo").Text,
                                    Width = "100",
                                    Render = new RenderPicture()
                                },
                                new ColumnProperty(nameof(ShippingProviderModel.DisplayOrder))
                                {
                                    Title = T("Admin.Configuration.Shipping.Providers.Fields.DisplayOrder").Text,
                                    Width = "100",
                                    ClassName = NopColumnClassDefaults.CenterAll,
                                    Editable = true,
                                    EditType = EditType.Number
                                },
                                new ColumnProperty(nameof(ShippingProviderModel.IsActive))
                                {
                                    Title = T("Admin.Configuration.Shipping.Providers.Fields.IsActive").Text,
                                    Width = "100",
                                    ClassName = NopColumnClassDefaults.CenterAll,
                                    Render = new RenderBoolean(),
                                    Editable = true,
                                    EditType = EditType.Checkbox
                                },
                                new ColumnProperty(nameof(ShippingProviderModel.SystemName))
                                {
                                    Title = T("Admin.Configuration.Shipping.Providers.Configure").Text,
                                    Width = "150",
                                    ClassName =  NopColumnClassDefaults.Button,
                                    Render = new RenderCustom("renderColumnConfigure")
                                },
                                new ColumnProperty(nameof(ShippingProviderModel.SystemName))
                                {
                                    Title = T("Admin.Common.Edit").Text,
                                    Width = "200",
                                    ClassName =  NopColumnClassDefaults.Button,
                                    Render = new RenderButtonsInlineEdit()
                                }
                            }
                    })
                    
                    <script>
                        function renderColumnConfigure(data, type, row, meta) {
                            if (row.ConfigurationUrl && row.ConfigurationUrl.length > 0) {
                                return '<a class="btn btn-default" href="' + row.ConfigurationUrl + '"><i class="fa fa-cog"></i>@T("Admin.Configuration.Shipping.Providers.Configure")</a>';
                            } else {
                                return '';
                            }
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
